package cn.test.my.excel.listdata;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;

/**
 * @author summit
 * @since 2021/7/8 20:50
 */
public class ListFill {

	public static void main(String[] args) throws IOException {
		List<String> headList = Arrays.asList("名字","开头","测试");
		List<List<String>> values = new ArrayList<>();
		values.add(Arrays.asList("1", "2", "3"));

		values.add(Arrays.asList("3", "2", "1"));
		ExcelEasyExport.startExport(new FileOutputStream("D:\\test\\222.xls"), headList, values);
//		HSSFWorkbook workbook = new HSSFWorkbook();
//		OutputStream os = new FileOutputStream("D:\\test\\students.xls");
//		HSSFSheet sheet = workbook.createSheet("test");
//
//		CellStyle style = getCellStyle(workbook);
//
//
//		int index = 0;
//		HSSFRow headRow = sheet.createRow(index);
//		int headNum = 0;
//		for (String h : headList) {
//			HSSFCell cell = headRow.createCell(headNum++);
//			cell.setCellValue(h);
//			cell.setCellStyle(style);
//		}
//		for (List<String> value : values) {
//			index++;
//			HSSFRow row = sheet.createRow(index);
//			int num = 0;
//			for (String str : value) {
//				HSSFCell cell = row.createCell(num++);
//				cell.setCellValue(str);
//
//				cell.setCellStyle(style);
//			}
//		}
//		workbook.write(os);
//		os.close();
	}

	private static CellStyle getCellStyle(HSSFWorkbook workbook) {
		// 生成一个样式
		CellStyle style = workbook.createCellStyle();

		// 设置这些样式
		style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex());
		style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
		style.setBorderBottom(BorderStyle.THIN);
		style.setBorderLeft(BorderStyle.THIN);
		style.setBorderRight(BorderStyle.THIN);
		style.setBorderTop(BorderStyle.THIN);
		style.setAlignment(HorizontalAlignment.CENTER);
		// 生成一个字体
		HSSFFont font = workbook.createFont();
		font.setFontHeightInPoints((short) 11);
		font.setBold(false);
		// 把字体应用到当前的样式
		style.setFont(font);
		return style;
	}
}

